/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.socket.server.data_access_components;

/**
 *
 * @author CongChinh
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBAccessor {        
        private String  driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        
        private String path_to_db = "database/QuanLyXeMay.mdb";
        //private String path_to_db = "C:/QuanLyXeMay.mdb";
        private String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= "+ path_to_db;
        //private String  url = "jdbc:odbc:QuanLyXeMay";
        
        private String  username = "";
        private String  password = "";
        
        private Connection connection;       
        
        //connect to DB
        public boolean connectDB()
        {
            try {
                Class.forName(driver);
                connection = DriverManager.getConnection(url, username, password);
                //
                if (connection != null) {
                    return true;
                }
            } catch(ClassNotFoundException cnfe) {
                cnfe.printStackTrace();
            } catch(SQLException sqle) {
                sqle.printStackTrace();
            }
            return false;
        }
        //get connection
        public Connection getConnection() {
            return connection;
        }
}
